<?php
/**
 * Created by PhpStorm.
 * User: shutao
 * Date: 2018/11/13
 * Time: 13:45
 */

namespace wechat\models;

use tt\common\components\TtActiveRecord;
use yii\db\Migration;

/**
 * @property integer $id
 * @property integer $we_id
 * @property string $openid
 * @property string $user_openid
 * @property integer $type
 */
class WeUserOpenid extends TtActiveRecord
{
    public static function tableName()
    {
        return 'we_user_openid';
    }

    public function createTableWithName(Migration $migration, $tableName)
    {
        $migration->createTable($tableName, [
            'id' => $migration->primaryKey()->unsigned(),
            'we_id' => $migration->integer()->notNull()->unsigned()->comment($this->getAttributeLabel('we_id')),
            'openid' => $migration->string(100)->notNull()->comment($this->getAttributeLabel('openid')),
            'user_openid' => $migration->string(100)->notNull()->comment($this->getAttributeLabel('user_openid')),
            'type' => $migration->tinyInteger(1)->notNull()->defaultValue(0)->unsigned()->comment($this->getAttributeLabel('type'))
        ]);
        $migration->createIndex('we_id', $tableName, ['we_id']);
        $migration->createIndex('user_openid', $tableName, ['user_openid']);
    }

    public function attributeLabels()
    {
        return [
            'id' => '#',
            'we_id' => 'we.user.id',
            'openid' => 'we.config.appid',
            'user_openid' => '微信用户 openid',
            'type' => '类型'
        ];
    }

    public static function typeText($type = null)
    {
        return WeConfig::typeText($type);
    }
}